<template>
  <div class="swiper">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(img, idx) in imgurl" :key="idx">
        <img :src="img" alt="" />
      </swiper-slide>
      <!-- 分页器、前进/后退按钮 -->
      <div slot="pagination" class="swiper-pagination"></div>
      <div slot="button-prev" class="swiper-button-prev"></div>
      <div slot="button-next" class="swiper-button-next"></div>
    </swiper>
  </div>
</template>

<script>
// 1. 只在这一行引入
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css' // 样式仍要单独引入

export default {
  props: ['imgurl'],
  components: {
    // 2. 局部注册
    Swiper,
    SwiperSlide
  },
  data() {
    return {
      swiperOption: {
        loop: true,
        autoplay: {
          delay: 3000,
          disableOnInteraction: false
        },
        pagination: {
          el: '.swiper-pagination',
          clickable: true
        },
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        }
      }
    }
  }
}
</script>

<style>
.swiper {
  width: 100%;
  margin: 10px auto;
}
img {
  object-fit: contain;
}
</style>
